package com.usooft.metaTalent.admin.base;

import com.usooft.framework.web.upload.FileValidator;
import com.usooft.metaTalent.core.base.file.FileManager;
import lombok.RequiredArgsConstructor;
import org.apache.commons.io.FilenameUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Component
@RequiredArgsConstructor
public class FileUploader {

    private final FileManager fileManager;

    public String upload(MultipartFile file,
                         FileValidator fileValidator,
                         String path) throws IOException {
        fileValidator.validate(file);
        return fileManager.store(file.getInputStream(), path, FilenameUtils.getExtension(file.getOriginalFilename()));
    }

}
